package com.gitee.cashzhang27.test.cloud.docker.hello;

import com.gitee.cashzhang27.test.cloud.docker.hello.feign.HiFeign;
import java.io.File;
import java.io.IOException;
import java.util.Date;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.io.FileUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.cloud.client.SpringCloudApplication;
import org.springframework.cloud.openfeign.EnableFeignClients;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author Cash Zhang
 * @version v1.0
 * @since 2019/07/09 11:08
 */
@Slf4j
@RestController
@EnableFeignClients
@SpringCloudApplication
public class CloudDockerHelloApplication {



  @Value("${version}")
  private String version;

  @GetMapping("/")
  public String home() {
    return "Hello Docker World：" + version;
  }

  @Value("${user.home}")
  private String home;

  @GetMapping("/hello")
  public String hello() {
    System.out.println(new Date());
    return "Hello Docker World：" + home;
  }

  @Value("${test.test1}")
  private String test;

  @GetMapping("/testEnv")
  public String testEnv() {
    return test;
  }

  @GetMapping("/testFile")
  public void testFile() {
    String text = "123456";
    File file = new File("/file/" + System.currentTimeMillis() + ".txt");
    try {
      FileUtils.writeStringToFile(file, text,
          "utf-8");
    } catch (IOException e) {
      e.printStackTrace();
    }
  }

  @Autowired
  private HiFeign hiFeign;

  @GetMapping("/testHi")
  public void testHi(){
    hiFeign.home();
    System.out.println(1);
  }


  public static void main(String[] args) {
    SpringApplication.run(CloudDockerHelloApplication.class, args);
  }


}
